home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / fact.doc < prev    next >
Text File  |  1995-03-31  |  3KB  |  61 lines

  1. (Comp.sys.handhelds) 
  2. Item: 2193 by jurjen at cwi.nl 
  3. Author: [Jurjen NE Bos] 
  4.   Subj: HP48: Fast & Accurate Complex Factorial 
  5.   Date: Mon Feb 25 1991 
  6.  
  7. - load the library in your HP48 
  8. - store it in a port by typing <port> STO (for example, 0 STO) 
  9. - turn your calculator off and on (you'll lose your stack!) 
  10. - enter 1617 ATTACH in the directory where you intend to use it 
  11.  
  12. Now you have remapped the FACT function to a special version that also takes 
  13. complex arguments. 
  14.  
  15. Features: 
  16. -   FACT of a name or algebraic gives ! instead.  To make a function that works 
  17.     with both algebraics and complex numbers, use the user function: 
  18.     FAC @warning: typed in by hand, download with caution 
  19.     %%HP: T(3); 
  20.       \<< \-> z 
  21.          \<< 
  22.            IF { 6 7 9 } z TYPE POS 
  23.            THEN z 1 \->LIST 'FAC' APPLY 
  24.            ELSE z FACT 
  25.            END 
  26.          \>> 
  27.        \>> 
  28.     This program should be called FAC. 
  29.     This should be downloaded or typed in AFTER you installed the library. 
  30.     Sorry for the inconvenience; as far as I know, it is impossible to 
  31.     incorporate library functions into an algebraic. 
  32. -   The library is only 495.5 bytes. 
  33. -   For real arguments, the program is identical to !. 
  34. -   This program is extremely accurate, because it uses Long Real and Long 
  35.     Complex internally.  The accuracy is more than 11 digits (most of the time 
  36.     all digits are correct), even around the poles. 
  37. -   The program is fast, because it uses internal functions only.  Of course, 
  38.     a complex factorial is hard to compute, so it still takes 540 milliseconds 
  39.     to compute (5 3) FACT.  As far as I know, the maximum computation time is 
  40.     875 milliseconds. (For real arguments, it can go up to 2180 milliseconds!) 
  41. -   The algorithm used is: 
  42.         For real numbers, ! is called. 
  43.         For numbers with real part >-6: the same algorithm as HP uses.  I will 
  44.         not tell you what it is, because it is probably patented.  I will only 
  45.         tell you that I did not see it before, and that it is fast and 
  46.         accurate.  Of course, the algorithm had to be adapted for complex 
  47.         numbers. 
  48.         For number with real part <-6, I use the formula: 
  49.                          pi * x 
  50.         FACT(X) = -------------------- 
  51.                   sin(pi*x) * FACT(-X) 
  52.         The sine is compute using degrees for the real part of x to preserve 
  53.         accuracy around the poles. 
  54. -   Note that -250.000000001 FACT is slower (and less accurate) than 
  55.     (-250.000000001 0) FACT. 
  56. -   Weird errors or results can occur if an error occurs during the 
  57.     computation. I have not see this happen, and I only expect it to happen for 
  58.     extremely large arguments (absolute value > 10000). 
  59.  
  60. Have fun! 
  61.